package com.yuanian.timingwheel.bootstrap;


import com.yuanian.timingwheel.facade.TwManager;
import com.yuanian.timingwheel.model.task.AttachTask;
import com.yuanian.timingwheel.model.task.FixedDateTask;
import com.yuanian.timingwheel.model.task.IntervalTask;
import com.yuanian.timingwheel.model.task.base.BaseTask;
import com.yuanian.timingwheel.model.timingwheel.bucket.BucketQueue;
import com.yuanian.timingwheel.redis.RedisServiceImpl;
import com.yuanian.timingwheel.test.CommonService;
import com.yuanian.timingwheel.test.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Random;

@Component
public class BootStrap implements CommandLineRunner {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void run(String... args) throws Exception {
      /*  BucketQueue bucketQueue = new BucketQueue(1111);
        bucketQueue.push(new BaseTask("xxxx", 1000L, 1000L, new Date(), "yyyy"));
        redisTemplate.opsForHash().put("htliu-job:20221026", "1111", bucketQueue);

        BucketQueue bucketQueue1 = new BucketQueue(2222);
        redisTemplate.opsForHash().put("htliu-job:20221026", "2222", bucketQueue1);

        BucketQueue bucketQueue2 = (BucketQueue) redisTemplate.opsForHash().get("htliu-job:20221026", "1111");
        System.out.println(bucketQueue2.pop());*/
        TwManager.getInstance().start();
       /* for (int i = 0; i < 1; i++) {
            Thread s1 = new Thread(new Runnable() {
                @Override
                public void run() {
                    int cnt = 0;
                    while (cnt < 10000) {


                        FixedDateTask task = new FixedDateTask(new Date(new Date().getTime() + 180000 + 100*cnt), "xxx");

                        try {
                            task.createTaskMethod("run", "person", null);
                            task.setTaskDesc(1000 + "");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        AttachTask attachTask = new AttachTask("附属任务");
                        try {
                            attachTask.createTaskMethod("run2", "person", null);
                            attachTask.setTaskDesc(10000 + "");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        task.addAttachTask(attachTask);
                        //task.executionTime = new Date(System.currentTimeMillis() + i * 1000);
                        TwManager.getInstance().saveTask(task);
                        cnt++;
                    }
                }
            });
            s1.start();

        }*/

        //redisService.set("htliu-job:20221026:load", "xxx");

    }
}
